import Vue from 'vue';
import uView from "uview-ui";
import App from './App';

import '@/static/mobile-font/index.css';
import * as onlineDict from '@/staticDict/onlineStaticDict.js';
import * as flowDict from '@/staticDict/flowStaticDict.js';
import * as staticDict from '@/staticDict/index.js';
import * as reportDict from '@/staticDict/reportStaticDict.js';
import * as ajax from '@/common/ajax.js';
import theme  from 'uni.scss';

import OnlineCustomBlock from '@/views/components/Online/OnlineCustomBlock.vue';
import OnlineForm from '@/views/online/index.vue';
import OnlineCustomFilterBox from '@/views/components/Online/OnlineCustomFilterBox.vue';
import OnlineCustomImage from '@/views/components/Online/OnlineCustomImage.vue';
import OnlineImageCard from '@/views/components/Online/OnlineImageCard.vue';
import OnlineRelationSelect from '@/views/components/Online/OnlineRelationSelect.vue';
import OnlineCustomChart from '@/views/components/Online/OnlineCustomChart.vue';
import OnlineCustomTabs from '@/views/components/Online/OnlineCustomTabs.vue';
import OnlineCustomUpload from '@/views/components/Online/OnlineCustomUpload.vue';
import OnlineCustomList from '@/views/components/Online/OnlineCustomList.vue';
import UniEcCanvas from '@/views/components/uni-ec-canvas/uni-ec-canvas.vue';
import FieldRadio from '@/views/components/FieldRadio.vue';
import CustomText from '@/views/components/CustomText.vue';
import DeptSelect from '@/views/components/DeptSelect/index.vue';
import UserSelect from '@/views/components/UserSelect/index.vue';
import FieldLabel from '@/views/components/FieldLabel.vue';
import FieldInput from '@/views/components/FieldInput.vue';
import FieldCalendar from '@/views/components/FieldCalendar';
import FieldStepper from '@/views/components/FieldStepper';
import FieldSelect from '@/views/components/FieldSelect.vue';
import FieldSwitch from '@/views/components/FieldSwitch.vue';
import FieldCheckBox from '@/views/components/FieldCheckBox.vue';
import FieldRate from '@/views/components/FieldRate.vue';
import FieldCascader from '@/views/components/FieldCascader.vue';
import FieldUpload from '@/views/components/FieldUpload.vue';
import SignaturePad from '@/views/components/SignaturePad/index.vue';
import SearchFilter from '@/views/components/SearchFilter.vue';
import SelectFilter from '@/views/components/SelectFilter.vue';
import SwitchFilter from '@/views/components/SwitchFilter.vue';
import NumberRangeFilter from '@/views/components/NumberRangeFilter.vue';
import DateRangeFilter from '@/views/components/DateRangeFilter.vue';

import BasePage from '@/views/components/BasePage.vue';
import FilterBox from '@/views/components/FilterBox.vue';
import CustomImage from '@/views/components/CustomImage.vue';
import ImageCard from '@/views/components/ImageCard.vue';
import CustomList from '@/views/components/CustomList.vue';
import CardList from '@/views/components/CardList.vue';
// 图表
import LineChart from '@/views/components/Charts3.0/lineChart.vue';
import BarChart from '@/views/components/Charts3.0/barChart.vue';
import PieChart from '@/views/components/Charts3.0/pieChart.vue';
import FunnelChart from '@/views/components/Charts3.0/funnelChart.vue';
import RadarChart from '@/views/components/Charts3.0/radarChart.vue';
import ScatterChart from '@/views/components/Charts3.0/scatterChart.vue';
// #ifndef VUE3
Vue.config.productionTip = false
App.mpType = 'app'

import filePersistentIO from "./utils/filePersistentIO.js";
 
Vue.prototype.$filePersistentIO = filePersistentIO; // 文件缓存

// 引入全局 uView 框架
Vue.use(uView);

Vue.component('online-custom-block', OnlineCustomBlock);
Vue.component('online-form', OnlineForm);
Vue.component('online-filter-box', OnlineCustomFilterBox);
Vue.component('online-custom-image', OnlineCustomImage);
Vue.component('online-image-card', OnlineImageCard);
Vue.component('online-relation-select', OnlineRelationSelect);
Vue.component('online-custom-upload', OnlineCustomUpload);
Vue.component('online-custom-list', OnlineCustomList);
Vue.component('online-custom-chart', OnlineCustomChart);
Vue.component('online-custom-tabs', OnlineCustomTabs);
Vue.component('uni-ec-canvas', UniEcCanvas);
Vue.component('custom-text', CustomText);
Vue.component('field-radio', FieldRadio);
Vue.component('user-select', UserSelect);
Vue.component('dept-select', DeptSelect);
Vue.component('field-label', FieldLabel);
Vue.component('field-input', FieldInput);
Vue.component('field-calendar', FieldCalendar);
Vue.component('field-stepper', FieldStepper);
Vue.component('field-select', FieldSelect);
Vue.component('field-switch', FieldSwitch);
Vue.component('field-checkbox', FieldCheckBox);
Vue.component('field-rate', FieldRate);
Vue.component('field-cascader', FieldCascader);
Vue.component('field-upload', FieldUpload);
Vue.component('field-signature', SignaturePad);
Vue.component('search-filter', SearchFilter);
Vue.component('select-filter', SelectFilter);
Vue.component('switch-filter', SwitchFilter);
Vue.component('number-range-filter', NumberRangeFilter);
Vue.component('daterange-filter', DateRangeFilter);

Vue.component('base-page', BasePage);
Vue.component('filter-box', FilterBox);
Vue.component('custom-list', CustomList);
Vue.component('custom-image', CustomImage);
Vue.component('image-card', ImageCard);
Vue.component('card-list', CardList);
// 图表
Vue.component('line-chart', LineChart);
Vue.component('bar-chart', BarChart);
Vue.component('pie-chart', PieChart);
Vue.component('funnel-chart', FunnelChart);
Vue.component('radar-chart', RadarChart);
Vue.component('scatter-chart', ScatterChart);

import 'uview-ui/theme.scss';
import 'uni.scss';
import '@/core/mixins/index.js'

import '@/static/styles/reset.css'
import '@/static/styles/flex.css'
try {
	function isPromise(obj) {
		return (
			!!obj &&
			(typeof obj === "object" || typeof obj === "function") &&
			typeof obj.then === "function"
		);
	}

	// 统一 vue2 API Promise 化返回格式与 vue3 保持一致
	uni.addInterceptor({
		returnValue(res) {
			if (!isPromise(res)) {
				return res;
			}
			return new Promise((resolve, reject) => {
				res.then((res) => {
					if (res[0]) {
						reject(res[0]);
					} else {
						resolve(res[1]);
					}
				});
			});
		},
	});
} catch (error) {
	// todo
}
// console.log(ajax);
// #ifdef MP-WEIXIN
// 如果是微信小程序端，把所有的字典挂载上和doUrl方法
Vue.mixin({
	data() {
		return {
			...staticDict,
			...onlineDict,
			...flowDict,
			...reportDict,
			theme
		}
	},
	methods: {
		...ajax.default
	}
})
// #endif
Vue.prototype.theme = theme

const app = new Vue({
	...App
})
app.$mount()
// #endif

// #ifdef VUE3
import {
	createSSRApp
} from 'vue'
export function createApp() {
	const app = createSSRApp(App)

	return {
		app
	}
}
// #endif